from rest_framework.serializers import ModelSerializer

from apps.users.models import User


class UserSerilizer(ModelSerializer):
    #定义password2字段
    class Meta:
        model = User
        fields = '__all__'
        extra_kwargs = {
            'username':{
                'max_length':20,
                'min_length':5
            },
            'password':{
                'max_length': 20,
                'min_length': 8,
                'write_only':True
            }
        }
    def create(self, validated_data):
        #里面自动验证了
        return User.objects.create_user(**validated_data)

#因为要自定义长度限制
# class UserAddSerializer(ModelSerializer):
#     class Meta:
#         model =